<style>
</style>
<template>
  <list_url ref="list_url" :config="config" style="">
    <template #value="{row}">
      <component v-if="row.type" :is="row.type" is_info="1" no_table="1" :value="row.value" :config="row.config" ></component>
    </template>
    <template #action="{row}">
      <el-button  @click="to_edit(row)" size="small">编辑</el-button>
    </template>
  </list_url>
</template>
<script>
export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');
    if(in_right_admin('Config/add_extend')) btns['添加'] = function(){ app.iframe('edit_extend') }
    if(in_right_admin('Config/delete_extend')) btns['彻底删除'] = function(){
      app.$refs['list_url'].ids_action("", "delete_extend", "", {action_label:"彻底删除"})
    }

    let forms_config = {
      tips_value: {label:'关键词',name:'where[tips|value][like]',type:'text_one',value:''},
    };
    let type_map = this.field_type(this.field_type.CAN_CONFIG, 'label');
    let group_map = {
      'personalization_param': '个性化参数',
    }
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left', type: 'hidden', order:true},
      group: {name:'group', label:'配置组',width:'100px',type:'select_one',config:group_map},
      name: {name:'name', label:'配置名',width:'180px', align:'left', remove:true},
      tips: {name:'tips', label:'配置说明',type:'text_more',min_width:'100px'},
      value: {name:'value', label:'值',type:'value', min_width:'100px'},
      type: {name:'type', label:'组件类型',width:'100px',type:'select_one',config:type_map},
      status: {name:'status', label:'状态',type:'radio_switch',config:'失效|0,有效|1',width:'80px', can_edit:true, onchange:this.edit},
    };
    list_cols['action'] = {name:'action', label:'操作', width:'150px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/config/'+(is_del?'recycle':'list_extend'),
        title: "扩展配置列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
      },
      change_ing: false,
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('Config/edit_extend');
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      this.iframe('edit_extend?'+s94Mjs.param_encode(param))
    },
    edit(row,col,v){
      if (this.change_ing) return false;
      let app = this;
      let can_edit = in_right_admin('Config/edit_extend');
      if (can_edit){
        this.change_ing = true;
        ajax(`/admin/config/edit_extend?id=${row.id}&${col.name}=${v}`, (res)=>{
          row[col.name] = v;
          app.change_ing = false;
        })
      }
      return false;
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
